#include "SMPPBroadcastResponseOptionalTLVs.hpp"

using namespace smpp::pdu;

BroadcastResponseOptionalTLVs::BroadcastResponseOptionalTLVs(
const BroadcastErrorStatus *nBroadcastErrorStatus,
const FailedBroadcastAreaIdentifier *nFailedBroadcastAreaIdentifier):
_BroadcastErrorStatus(0),_FailedBroadcastAreaIdentifier(0){
	if(nBroadcastErrorStatus)
		_BroadcastErrorStatus = new BroadcastErrorStatus(
		*nBroadcastErrorStatus);
	if(nFailedBroadcastAreaIdentifier)
		_FailedBroadcastAreaIdentifier = 
		new FailedBroadcastAreaIdentifier(*nFailedBroadcastAreaIdentifier);
}

BroadcastResponseOptionalTLVs::BroadcastResponseOptionalTLVs(
const BroadcastResponseOptionalTLVs &nBroadcastResponseOptionalTLVs):
_BroadcastErrorStatus(0),_FailedBroadcastAreaIdentifier(0){
	if(nBroadcastResponseOptionalTLVs.getBroadcastErrorStatus())
		_BroadcastErrorStatus = new BroadcastErrorStatus(
		*nBroadcastResponseOptionalTLVs.getBroadcastErrorStatus());
	if(nBroadcastResponseOptionalTLVs.getFailedBroadcastAreaIdentifier())
		_FailedBroadcastAreaIdentifier = new FailedBroadcastAreaIdentifier(
		*nBroadcastResponseOptionalTLVs.getFailedBroadcastAreaIdentifier());
}

BroadcastResponseOptionalTLVs::~BroadcastResponseOptionalTLVs(){
	if(_BroadcastErrorStatus)
		delete _BroadcastErrorStatus;
	if(_FailedBroadcastAreaIdentifier)
		delete _FailedBroadcastAreaIdentifier;
}

void BroadcastResponseOptionalTLVs::setBroadcastErrorStatus(
	const BroadcastErrorStatus *nBroadcastErrorStatus){
	if(_BroadcastErrorStatus){
		delete _BroadcastErrorStatus;
		_BroadcastErrorStatus = 0;
	}
	if(nBroadcastErrorStatus)
		_BroadcastErrorStatus = 
		new BroadcastErrorStatus(*nBroadcastErrorStatus);
}

const BroadcastErrorStatus *
	BroadcastResponseOptionalTLVs::getBroadcastErrorStatus() const{
	return _BroadcastErrorStatus;
}

void BroadcastResponseOptionalTLVs::setFailedBroadcastAreaIdentifier(
	const FailedBroadcastAreaIdentifier
	* nFailedBroadcastAreaIdentifier){
	if(_FailedBroadcastAreaIdentifier){
		delete _FailedBroadcastAreaIdentifier;
		_FailedBroadcastAreaIdentifier = 0;
	}
	if(nFailedBroadcastAreaIdentifier)
		_FailedBroadcastAreaIdentifier = 
		new FailedBroadcastAreaIdentifier(
		*nFailedBroadcastAreaIdentifier);
}

const FailedBroadcastAreaIdentifier *
	BroadcastResponseOptionalTLVs::getFailedBroadcastAreaIdentifier() 
	const{
	return _FailedBroadcastAreaIdentifier;
}

const quint16 BroadcastResponseOptionalTLVs::getLength() const{
	quint16 length(0);
	if(_BroadcastErrorStatus)
		length += 4 + _BroadcastErrorStatus->getLength();
	if(_FailedBroadcastAreaIdentifier)
		length += 4 + _FailedBroadcastAreaIdentifier->getLength();
	return length;
}
